<%@page import="com.itheima.store.domain.Book"%>
<%@page import="com.itheima.store.service.impl.BookServiceImpl"%>
<%@page import="com.itheima.store.service.BookService"%>
<%@page import="com.itheima.store.utils.CookieUtils"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>

<!doctype html>
<html>

	<head>
		<meta charset="utf-8" />
		<meta name="viewport" content="width=device-width, initial-scale=1">
		<title>安城金融图书管理平台</title>
		<!-- 引入自定义css文件 style.css -->
		<link rel="stylesheet" href="css/style.css" type="text/css" />
<link rel="stylesheet" href="${ pageContext.request.contextPath }/css/bootstrap.min.css" type="text/css" />
<script src="${ pageContext.request.contextPath }/js/jquery-1.11.3.min.js" type="text/javascript"></script>
<script src="${ pageContext.request.contextPath }/js/bootstrap.min.js" type="text/javascript"></script>
		
		<style>
			body {
				margin-top: 20px;
				margin: 0 auto;
				width: 100%;
			}
			.carousel-inner .item img {
				width: 100%;
				height: 300px;
			}
		</style>
	</head>

	<body>
		
		<%@ include  file="menu.jsp" %>

		<div class="row" style="width:1210px;margin:0 auto;">
			<div class="col-md-12">
				<ol class="breadcrumb">
					<li><a href="${ pageContext.request.contextPath }/index.jsp">首页</a></li>
				</ol>
			</div>
			<c:if test="${ pageBean.list.size() ==0 }">
				<div style="margin-left: 10%"><font style="font-weight:bold;font-size:30px;color:red;">图书馆还没有此类图书，如有需要，可联系管理员购买！</font></div>
			</c:if>
			<c:if test="${ pageBean.list.size() !=0 }">
				<c:forEach var="p" items="${ pageBean.list }">
				<div class="col-md-2">
					<a href="${ pageContext.request.contextPath }/BookServlet?method=findByBook_id&book_id=${p.book_id}">
						<img src="${ pageContext.request.contextPath }/${p.book_image}" width="170" height="170" style="display: inline-block;">
					</a>
					<p><a href="${ pageContext.request.contextPath }/BookServlet?method=findByBook_id&book_id=${p.book_id}" style='color:green'>${ fn:substring(p.book_name,0,7) }</a></p>
					<p><font color="#FF0000">库存：${ p.inventory }</font></p>
				</div>
				</c:forEach>
			</c:if>

		</div>



		<!-- 分页内容 -->
		
				<div style="text-align: center;">
				<ul class="pagination">
					<c:if test="${empty param.book_category_id}">
						<!-- 需要增加判断如果当前页面是第一页则不让跳转，否则进行向前 -->
					<c:if test="${ pageBean.currPage ==1 }">
						<li class="disabled"  aria-label="Previous"><span aria-hidden="true">&laquo;</span></li>
					</c:if>
					<c:if test="${ pageBean.currPage !=1 }">
						<li ><a href="${ pageContext.request.contextPath }/BookServlet?method=searchBook&currPage=${pageBean.currPage-1}&book_name=${bookName}&search=0" aria-label="Previous"><span aria-hidden="true">&laquo;</span></a></li>
					</c:if>
					
					<c:forEach var="i" begin="1" end="${ pageBean.totalPage }">
						<li <c:if test="${ pageBean.currPage == i }">class="active"</c:if>><a href="${ pageContext.request.contextPath }/BookServlet?method=searchBook&currPage=${i}&book_name=${bookName}&search=0">${ i }</a></li>
					</c:forEach>
					<c:if test="${ pageBean.currPage == pageBean.totalPage }">
						<li class="disabled">
							<a href="#" aria-label="Next">
								<span aria-hidden="true">&raquo;</span>
							</a>
						</li>
					</c:if>
					<c:if test="${ pageBean.currPage != pageBean.totalPage }">
						<li>
							<a href="${ pageContext.request.contextPath }/BookServlet?method=searchBook&currPage=${pageBean.currPage+1}&book_name=${bookName}&search=0" aria-label="Next">
								<span aria-hidden="true">&raquo;</span>
							</a>
						</li>
					</c:if>
					</c:if>
<%-- 					<li <c:if test="${ pageBean.currPage == 1 }">class="disabled"</c:if>><a href="${ pageContext.request.contextPath }/AdminUserServlet?method=findUserAllPageBean&currPage=${pageBean.currPage-1}" aria-label="Previous"><span aria-hidden="true">&laquo;</span></a></li>
 --%>					
 					<c:if test="${not empty param.book_category_id}">
					<!-- 需要增加判断如果当前页面是第一页则不让跳转，否则进行向前 -->
					<c:if test="${ pageBean.currPage ==1 }">
						<li class="disabled"  aria-label="Previous"><span aria-hidden="true">&laquo;</span></li>
					</c:if>
					<c:if test="${ pageBean.currPage !=1 }">
						<li ><a href="${ pageContext.request.contextPath }/BookServlet?method=findByBook_category_id&currPage=${pageBean.currPage-1}&book_category_id=${ param.book_category_id}" aria-label="Previous"><span aria-hidden="true">&laquo;</span></a></li>
					</c:if>
					
					<c:forEach var="i" begin="1" end="${ pageBean.totalPage }">
						<li <c:if test="${ pageBean.currPage == i }">class="active"</c:if>><a href="${ pageContext.request.contextPath }/BookServlet?method=findByBook_category_id&currPage=${i}&book_category_id=${ param.book_category_id}">${ i }</a></li>
					</c:forEach>
					<c:if test="${ pageBean.currPage == pageBean.totalPage }">
						<li class="disabled">
							<a href="#" aria-label="Next">
								<span aria-hidden="true">&raquo;</span>
							</a>
						</li>
					</c:if>
					<c:if test="${ pageBean.currPage != pageBean.totalPage }">
						<li>
							<a href="${ pageContext.request.contextPath }/BookServlet?method=findByBook_category_id&currPage=${pageBean.currPage+1}&book_category_id=${ param.book_category_id}" aria-label="Next">
								<span aria-hidden="true">&raquo;</span>
							</a>
						</li>
					</c:if>
					</c:if>
				</ul>
			</div>




		<!--
       		商品浏览记录:
        -->
		<div style="width:1210px;margin:0 auto; padding: 0 9px;border: 1px solid #ddd;border-top: 2px solid #999;height: 246px;">

			<h4 style="width: 50%;float: left;font: 14px/30px " 微软雅黑 ";">浏览记录</h4>
			<div style="clear: both;"></div>

			<div style="overflow: hidden;">

				<ul style="list-style: none;">
				<%
					Cookie[] cookies = request.getCookies();
				    Cookie cookie = CookieUtils.findCookie(cookies, "history");
				    BookService bookService = new BookServiceImpl();
				    if(cookie == null){
				    	out.println("<h3>您还没有浏览记录！</h3>");
				    }else{
				    	String value = cookie.getValue(); // 1-2-3
				    	String[] ids = value.split("-");
				    	for(String id:ids){
				    		Book b = bookService.findByBook_id(id);
				    		pageContext.setAttribute("p", b);
				%>    	
				<li style="width: 150px;height: 216;float: left;margin: 0 8px 0 0;padding: 0 18px 15px;text-align: center;"><img src="${ pageContext.request.contextPath }/${p.book_image}" width="130px" height="130px" /></li>
				<%  		
				    	}
				    }
				%>
					
				
				</ul>

			</div>
		</div>
		<%@ include file="under.jsp" %>

	</body>

</html>